﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnumExtension
{
    class Program
    {
        static void Main(string[] args)
        {
            //create a new user
            User admin = new User();
            admin.Permissions = PermissionTypes.Read
                | PermissionTypes.Write
                | PermissionTypes.Delete;
            //check for permissions
            bool canRead = ((PermissionTypes.Read & admin.Permissions) == PermissionTypes.Read);
            bool canWrite = ((PermissionTypes.Write & admin.Permissions) == PermissionTypes.Write);
            bool canCreate = ((PermissionTypes.Create & admin.Permissions) == PermissionTypes.Create);

            //and the results
            Console.WriteLine(canRead); //true
            Console.WriteLine(canWrite); //true
            Console.WriteLine(canCreate); //false

            //start with a value
            PermissionTypes permissions = PermissionTypes.Read | PermissionTypes.Write;

            //then check for the values
            canRead = permissions.Has(PermissionTypes.Read); //true
            canWrite = permissions.Has(PermissionTypes.Write); //true
            bool canDelete = permissions.Has(PermissionTypes.Delete); //false

            Console.ReadLine();
        }
    }
}
